<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace plugins\captcha;
//Demo插件英文名，改成你的插件英文就行了
use cmf\lib\Plugin;

/**
 * CaptchaPlugin
 */
class CaptchaPlugin extends Plugin
{
    public $types = ['1234567890',
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
        '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
    ];

    public $info = [
        'name' => 'Captcha',
        'title' => '图片验证码设置插件',
        'description' => '图片验证码设置插件',
        'status' => 1,
        'author' => 'MTJO',
        'version' => '1.0'
    ];

    public $has_admin = 0;//插件是否有后台管理界面

    public function install() //安装方法必须实现
    {
        return true;//安装成功返回true，失败false
    }

    public function uninstall() //卸载方法必须实现
    {
        return true;//卸载成功返回true，失败false
    }

    public function captchaImage($param)
    {
        $captcha = $this->getConfig();
        if ($captcha['type'] == 3) {
            $codeSet = $this->types[2];
            $captcha['useZh'] = 1;
        } else {
            $codeSet = $this->types[$captcha['type']];
        }

        $captcha['codeSet'] = $codeSet;
        unset($captcha['type']);

        $bg = explode(',', $captcha['bg']);
        array_walk($bg, 'intval');
        if (count($bg) > 2 && $bg[0] < 256 && $bg[1] < 256 && $bg[2] < 256) {
            $captcha['bg'] = $bg;
        } else {
            $captcha['bg'] = '';
        }

        foreach ($captcha as $k => &$v) {
            //echo $k.' '; var_dump(empty($v));
            //接收前台长宽
            if (in_array($k,['imageW','imageH'] )&&isset($param[$k]) && $param[$k] > 0) {
                $v = $param[$k];
            }
        }
//        print_r($captcha);
//        exit;
        config('captcha', $captcha);
    }

}